﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameBase
{
    public class Visble3DObject : VisibleObject
    {
        protected float z = 0;
        protected float maxDepth = 1;

        public Visble3DObject()
        {
        }
        public Visble3DObject(string filePath,int row,int col)
            :base(filePath, row, col)
        {
        }

        public Visble3DObject(string filePath, int row, int col, Vector3 position)
            :base(filePath, row, col)
        {
            Position3D = position;
        }
        public float MaxDepth
        {
            get { return maxDepth; }
            set { maxDepth = value; }
        }
        public Vector3 Position3D
        {
            get { return new Vector3(position, z); }
            set {
                Position = new Vector2(value.X, value.Y);
                z = value.Z; 
            }
        }

        public Vector3 GetDrawPosition(Camara camara,Viewport viewport)
        {
            return camara.Project(Position3D,viewport);
        }
        public override float GetDrawScale()
        {
            return scale*baseScale * (maxDepth / (maxDepth - z));
        }
        public float GetDrawDepth()
        {

            float depth;
            if (z < 0)
            {
                depth = 1;
            }
            else
            {
                depth = 1 - z * 0.9f / maxDepth;
            }

            return depth;
        }
        public virtual void Draw(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Vector3 position)
        {
            
            if (z >= maxDepth)
                return;
            
            //float drawScale = GetDrawScale() * (viewPoint/(viewPoint-z));
            
            Sprite.Draw(gameTime, spriteBatch,
                new Vector2(position.X,position.Y),
            GetDrawRotate(), GetDrawScale(), GetDrawDepth());
        }
   /*     public override Rectangle  GetBound()
        {
 	        return base.GetBound();
        }*/
    
    }
}
